/**
 * @author zhaozhenjiang
 * 创建数据库安装脚本
 * */

package com.auto.oracle;

final class installDbShell {
	private createFile shell = null;
	private String BASE_PATH = null;
	private createParams para = null;
	
	public installDbShell(String base_path,String shell_name,createParams para){
		shell = new createFile(base_path, shell_name);
		BASE_PATH = base_path;
		this.para = para;
	}
	
	public void createFile(){
		shell.init();
		shell.append("#/bin/sh!");
		shell.append("rm -f /home/oracle/.listener.sh");
		shell.append("rm -f /home/oracle/.createdb.sql");
		shell.append("rm -f /home/oracle/.init*.ora");
		shell.append("rm -f /home/oracle/.createDb.sh");
		shell.append("cp " + BASE_PATH + "/.createdb.sql /home/oracle/");
		shell.append("cp " + BASE_PATH + "/.init.ora /home/oracle/.init" + para.getInstanceName() + ".ora");
		shell.append("cp " + BASE_PATH + "/.listener.sh /home/oracle/");
		shell.append("cp " + BASE_PATH + "/.createDb.sh /home/oracle/");
		shell.append("chown oracle:oinstall /home/oracle/.listener.sh");
		shell.append("chown oracle:oinstall /home/oracle/.createdb.sql");
		shell.append("chown oracle:oinstall /home/oracle/.init*.ora");
		shell.append("chown oracle:oinstall /home/oracle/.createDb.sh");
		shell.append("chmod +x /home/oracle/.listener.sh");
		shell.append("chmod +x /home/oracle/.createDb.sh");
		shell.append("su - oracle << EOF");
		shell.append("/home/oracle/.listener.sh");
		shell.append("echo '" + para.getInstanceName() + ":" + para.getOraclePath() + "/app/oracle/product/" + para.getVersion() + "/db_1:Y' >> /etc/oratab");
		shell.append(para.getOraclePath() + "/app/oracle/product/" + para.getVersion() + "/db_1/bin/lsnrctl start");
		shell.append("mkdir -p " + para.getOraclePath() + "/app/oracle/admin/" + para.getInstanceName() + "/adump");
		shell.append("mkdir -p " + para.getOraclePath() + "/app/oracle/oradata/" + para.getInstanceName() + "");
		shell.append("mkdir -p " + para.getOraclePath() + "/app/oracle/flash_recovery_area");
		shell.append("cd " + para.getOraclePath() + "/app/oracle/product/" + para.getVersion() + "/db_1/dbs");
		shell.append("export ORACLE_SID=" + para.getInstanceName());
		shell.append(para.getOraclePath() + "/app/oracle/product/" + para.getVersion() + "/db_1/bin/orapwd file=orapw" + para.getInstanceName() + " password=" + para.getDatabasePwd() + " entries=30");
		shell.append("cp /home/oracle/.init" + para.getInstanceName() + ".ora " + para.getOraclePath() + "/app/oracle/product/" + para.getVersion() + "/db_1/dbs/init" + para.getInstanceName() + ".ora");
		shell.append("/home/oracle/.createDb.sh");
		shell.append("exit;");
		shell.append("EOF");
		shell.close();
		shell = null;
	}	

	@SuppressWarnings("unused")
	private class Decompile{
		
	}
}
